package itsm.isperp.module.service.app;

import itsm.isperp.framework.core.context.ContextHolder;
import itsm.isperp.framework.data.commons.repository.BaseRepository;
import itsm.isperp.framework.service.BaseService;
import itsm.isperp.module.entity.app.AppMessageRemind;
import itsm.isperp.module.repository.app.AppMessageRemindMapper;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

@Service
public class AppMessageRemindService extends BaseService<AppMessageRemind> {

	@Autowired
	protected AppMessageRemindMapper appMessageRemindMapper;

	@Override
	public BaseRepository<AppMessageRemind> getRepository() {
		return this.appMessageRemindMapper;
	}

	public void updateBusinessMsgRemind(AppMessageRemind entity) {
		// 更新跟踪消息到业务表
		String sql = "";
		String sourceType = entity.getSourceType();
		String sourceId = entity.getSourceId();
		String msgRemind = entity.getContent();
		switch (sourceType) {
		case "incident":
			sql = "update icd_incident set msg_remind='" + msgRemind
					+ "',msg_remind_date=sysdate where id='" + sourceId + "'";
			break;
		case "task":
			sql = "";
			break;
		case "request":
			sql = "update req_item set msg_remind='" + msgRemind
					+ "',msg_remind_date=sysdate where id='" + sourceId + "'";
			break;

		case "topic":
			sql = "update topic_topic set msg_remind='" + msgRemind
					+ "',msg_remind_date=sysdate where id='" + sourceId + "'";
			break;
		}
		if (StringUtils.isNotEmpty(sql)) {
			JdbcTemplate jdbcTemplate = ContextHolder
					.getSpringBean("jdbcTemplate");
			jdbcTemplate.execute(sql);
		}

	}

}
